clear
clear matrix
clear mata
program drop _all
set more off
set emptycells drop
set maxvar 100000
tempfile main


cd "<directory>"

*The code in this .do file reads in the dataset created in Data Cleaning Step 2.do and runs the code for Figure 1;

u final_dataset,clear
tempfile mainforgraph
sa `mainforgraph',replace


tempfile transfer dpo
u `mainforgraph',clear
keep if transfer==1 | dpopp_indic_base==1 | dpopp_indic==1 | dpopp_indic2==1 | dpopp_indic3==1
collapse (sum) transfer (max) distyear distmonth,by(distym)
sa `transfer',replace

u `mainforgraph',clear
keep if dpopp_indic_base==1 | dpopp_indic==1 | dpopp_indic2==1 | dpopp_indic3==1
collapse (max) dpopp_indic_base dpopp_indic dpopp_indic2 dpopp_indic3 dpopp_indic_basedate dpopp_indicdate dpopp_indic2date dpopp_indic3date,by(dosname masterloanidtrepp)
foreach var of varlist dpopp_indic_basedate dpopp_indicdate dpopp_indic2date dpopp_indic3date {
	gen `var'year=year(`var')
	gen `var'month=month(`var')
	gen `var'_ym=ym(`var'year,`var'month)
	form `var'_ym %tm
}
collapse (sum) dpopp_indic_base (max) dpopp_indic_basedateyear dpopp_indic_basedatemonth ,by(dpopp_indic_basedate_ym)
ren dpopp_indic_basedate_ym distym
keep dpopp_indic_base distym
sa `dpo',replace

u `transfer',clear
merge 1:1 distym using `dpo'
replace dpopp_indic_base=0 if dpopp_indic_base==.  
label var dpopp_indic_base "DPOs"
label var transfer "Transfers"
label var distym "Month"
form distym %tm
egen total_before=sum(dpopp_indic_base) if distym<=596 
egen total_after=sum(dpopp_indic_base) if distym>=598 & distym<=620
line transfer dpopp_indic_base distym if distym>=572 & distym<=620,xline(596) xlabel(572(3)620, labsize(small) angle(45)) ytitle("Count") lpattern(solid dash) lcolor(black black)
graph save "Graph" "<directory>",replace
graph export "<directory>", as(png) name("Graph") replace